import app
import unittest
from api.login import *
from unnite import assion_case
# 创建测试类
#     前置
#     后置
#     定义测试用例
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_data = LoginAPI()
    def tearDown(self):
        pass

    def test01_case001(self):
        response = self.login_data.login({"mobile":"13761905465","password":"123456"})
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertIn(True, response.json().get("success"))
        # self.assertIn(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        assion_case(self,response)#或者默认值

        #提取token信息
        app.TOKEN = "Bearer " + response.json().get("data")
        print(app.TOKEN)
        app.headers_data["Authorization"] = app.TOKEN


    def test02_case002(self):
        response = self.login_data.login({"mobile":"","password":"123456"})
        print(response.json())
        self.assertEqual(200, response.status_code)
        self.assertIn(False, response.json().get("success"))
        self.assertIn(20001, response.json().get("code"))
        self.assertIn("用户名或密码错误", response.json().get("message"))

        assion_case(self, response)  # 或者默认值

    def test03_case003(self):
        response = self.login_data.login({"mobile":"13800000002","password":"123456"})
        print(response.json())
        self.assertEqual(200, response.status_code)
        self.assertIn(False, response.json().get("success"))
        self.assertIn(20001, response.json().get("code"))
        self.assertIn("用户名或密码错误", response.json().get("message"))

